#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mem(x) memset(x,0,sizeof(x))
#define endl "\n"
#define printYes cout << "Yes\n"
#define printYES cout << "YES\n"
#define printNo cout << "No\n"
#define printNO cout << "NO\n"
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define mkp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,j,k) for (int i=(j);i<=(k);i++)
#define per(i,j,k) for (int i=(j);i>=(k);i--)
#define pcnt(x) __builtin_popcount(x)
mt19937 rnd(time(0));
template<class T>void chkmin(T&x,T y){x=min(x,y);}
template<class T>void chkmax(T&x,T y){x=max(x,y);}

const ll inf=1000000000000000000; 
//const ll inf=1000000000;
//const ll mod=998244353;
//const ll mod=1000000007;

const int N=400505;
int n,m,q,k; 

int fa[N][21],deth[N];
int LCA(int u,int v)
{
	if (deth[u]<deth[v]) swap(u,v);
	per(i,20,0) if (deth[fa[u][i]]>=deth[v]) u=fa[u][i];
	if (u==v) return u;
	per(i,20,0) if (fa[u][i]!=fa[v][i]) u=fa[u][i],v=fa[v][i];
	return fa[u][0];
}
int a[N],b[N],dfn[N];
namespace xutree
{
	vector<int>G[N];
	inline void add(int x,int y)
	{
		//cout << x << " " << y << endl;
		G[x].push_back(y);
	}
	bool cmp(int x,int y)
	{
		return dfn[x]<dfn[y];
	}
	void build(int num,int *a)
	{
		sort(a+1,a+num+1,cmp);
		static int st[N];
		int top=1;
		st[top]=1;
		for (int i=1;i<=num;i++)
		{
			int lc=LCA(st[top],a[i]);
			if (lc!=st[top])
			{
				while (deth[lc]<deth[st[top-1]])
				{
					add(st[top-1],st[top]);
					top--;
				}
				if (lc!=st[top-1])
				{
					add(lc,st[top]);
					st[top]=lc;
				}
				else
				{
					add(lc,st[top]);
					top--;
				}
			}
			st[++top]=a[i];
		}
		for (int i=1;i<top;i++) add(st[i],st[i+1]);
	}
	ll dp[N][5];
	
	void dfs(int u)
	{
		rep(i,0,k) dp[u][i]=0;
		for (int i:G[u])
		{
			dfs(i);
		}
		if (a[u]) 
		{
			dp[u][1]=1;
			G[u].clear();
			return;
		}
		dp[u][0]=1;
		for (int i:G[u])
		{
			static ll tmp[6];
			rep(j,0,k) tmp[j]=dp[u][j],dp[u][j]=0;
			dp[i][1]+=deth[i]-deth[u]-1;
			rep(j,0,k) rep(o,1,k-j) dp[u][j+o]+=tmp[j]*dp[i][o];
		}
		dp[u][1]++;
		G[u].clear();
	}
}
namespace tree
{
	vector<int>t[N];
	void add(int x,int y)
	{
		t[x].pb(y);
		//cout << x << " " << y << endl;
	}
	int tot,siz[N];
	void dfs(int x)
	{
		dfn[x]=++tot,siz[x]=1;
		for (int i:t[x])
		{
			dfs(i);
			siz[x]+=siz[i];
		}
	}
	bool check(int u,int v)
	{
		return (dfn[v]>=dfn[u])&&(dfn[v]<dfn[u]+siz[u]);
	}
	ll dp[N][5];
	int sum[N];
	void solve(int u)
	{
		rep(i,0,k) dp[u][i]=0;
		sum[u]=a[u];
		for (int i:t[u])
		{
			solve(i);
			sum[u]+=sum[i];
		}
		if (a[u]) 
		{
			if (b[u]==0) dp[u][1]=1;
			return;
		}
		dp[u][0]=1;
		if (sum[u]==0) return;
		for (int i:t[u])
		{
			if (sum[i]==0) continue;
			static ll tmp[6];
			rep(j,0,k) tmp[j]=dp[u][j],dp[u][j]=0;
			rep(j,0,k) rep(o,1,k-j) dp[u][j+o]+=tmp[j]*dp[i][o];
		}
		if (b[u]==0) dp[u][1]++;
	}
}
namespace graph
{
	vector<int>t[N],it[N];
	int d[N];
	void add(int x,int y)
	{
		t[x].pb(y),d[y]++;
		it[y].pb(x);
	}
	int id[N],tot;
	queue<int>q;
	void topo()
	{
		rep(i,1,n) if (d[i]==0) q.push(i);
		while (!q.empty())
		{
			int u=q.front();
			id[++tot]=u;
			q.pop();
			for (int i:t[u])
			{
				d[i]--;
				if (d[i]==0) q.push(i);
			}
		}
	}
	void build()
	{
		topo();
		deth[1]=1;
		rep(i,2,n)
		{
			int u=id[i],v=-1;
			for (int j:it[u])
			{
				if (v==-1) v=j;
				else v=LCA(v,j);
			}
			//assert(v>=1);
			fa[u][0]=v,deth[u]=deth[v]+1;
			tree::add(v,u);
			rep(k,1,20) fa[u][k]=fa[fa[u][k-1]][k-1];
		}
	}
	bool used[N];
	void update(int x)
	{
		rep(i,1,n) used[i]=0;
		used[x]=1;
		per(i,n,1)
		{
			int u=id[i];
			for (int j:t[u]) used[u]|=used[j];
		}
		rep(i,1,n) if (used[i]&&tree::check(i,x)==0) 
		{
			// if (i==1) cout << tree::check(i,x) << "???\n";
			b[i]=1;
		}
	}
}
void query()
{
	rep(i,1,n) b[i]=0;
	cin >> k;
	int num;
	cin >> num;
	vector<int>st;
	rep(i,1,num)
	{
		int x;
		cin >> x;
		st.pb(x);
	}
	if (k==1)
	{
		int ans=st[0];
		for (int i:st) ans=LCA(ans,i);
		cout << deth[ans] << endl;
		return;
	}
	if (m==n-1)
	{
		static int w[N];
		int cnt=0;
		for (int i:st) 
		{
			a[i]=1;
			if (i!=1) w[++cnt]=i;
		}
		xutree::build(cnt,w);
		xutree::dfs(1);
		cout << xutree::dp[1][k] << endl;
		for (int i:st) a[i]=0;	
		return;
	}
	// cout << SZ(st) << endl;
	for (int i:st) a[i]=1;
	for (int i:st) graph::update(i);
	// rep(i,1,n) cout << a[i] << " ";
	// cout << endl;
	// rep(i,1,n) cout << b[i] << " ";
	// cout << endl;
	tree::solve(1);
	cout << tree::dp[1][k] << endl;
	for (int i:st) a[i]=0;
	
}

int main()
{
	freopen("lodge.in","r",stdin);
	freopen("lodge.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin >> n >> m >> q;
	rep(i,1,m)
	{
		int x,y;
		cin >> x >> y;
		graph::add(x,y);
	}
	graph::build();
	tree::dfs(1);
	//chkmin(q,10);
	rep(i,1,q)
	{
		query();
	}
	return 0;
}
